package practice.observer;

import java.util.ArrayList;

/**
 * @ClassName Station
 * @Description TODO
 * @Author yaoqiang
 * @Date 2020/9/7 9:23
 * @Version 1.0
 */
public class Station implements Sub {
    private double humidity;
    private ArrayList<Obs> obsArrayList;

    public Station() {
        obsArrayList = new ArrayList<Obs>();
    }

    @Override
    public void addObs(Obs obs) {
        obsArrayList.add(obs);
    }

    @Override
    public void removeObs(Obs obs) {
        if (obsArrayList.contains(obs)) {
            obsArrayList.remove(obs);
        }
    }

    @Override
    public void notifyObs() {
        for (int i = 0; i < obsArrayList.size(); i++) {
            obsArrayList.get(i).update(humidity);
        }
    }

    public void update(double humidity) {
        this.humidity = humidity;
        notifyObs();
    }


    public double getHumidity() {
        return humidity;
    }

    public void setHumidity(double humidity) {
        this.humidity = humidity;
    }

    public ArrayList<Obs> getObsArrayList() {
        return obsArrayList;
    }

    public void setObsArrayList(ArrayList<Obs> obsArrayList) {
        this.obsArrayList = obsArrayList;
    }
}
